<?php
$this->breadcrumbs = array(
    'Jobs' => array('index'),
    $model->pdid,
);
?>
<?php $this->renderPartial('_menu',array(
	'model'=>$model,
)); ?>

<?php
$this->widget('application.extensions.fancybox.EFancyBox', array('target' => 'a.iframe', 'config' => array('width' => 800, 'height' => 600)));
?>

<h1>Assign Task #<?php echo $model->pdid; ?></h1>
<?php
$viewDate = $model;
$viewDate->dateline = date("Y-m-d H:i:s", $viewDate->dateline);
$viewDate->updated = date("Y-m-d H:i:s", $viewDate->updated);
$this->widget('zii.widgets.CDetailView', array(
    'data' => $viewDate,
    'attributes' => array(
        'pdid',
        'uid',
        'type',
        'time',
        'style',
        'dateline',
        'updated',
    ),
));
?>
<?php
$this->widget('zii.widgets.grid.CGridView', array(
    'afterAjaxUpdate' => "function(id,data){ $('a.iframe').fancybox({'width':800,'height':600}); }",
    'id' => 'person-task-grid',
    'dataProvider' => $searchTaskModel->belongSearch($model->pdid),
    'filter' => $searchTaskModel,
    'columns' => array(
        'tcode' => array(
            'name' => 'task.class.classname',
            'header' => 'Tcode',
            'headerHtmlOptions' => array('width' => '10%'),
            'htmlOptions' => array('style' => 'text-align:center;')
        ),
        'subcode' => array(
            'name' => 'task.task',
            'header' => 'Subcode',
            'headerHtmlOptions' => array('width' => '18%'),
            'htmlOptions' => array('style' => 'text-align:left;')
        ),
        'taskdetail' => array(
            'name' => 'task.taskdetail',
            'header' => 'Task',
            'headerHtmlOptions' => array('width' => '40%'),
        ),
        'urgency' => array(
            'name' => 'task.urgency',
            'header' => 'Urgency',
            'headerHtmlOptions' => array('width' => '8%'),
            'htmlOptions' => array('style' => 'text-align:center;')
        ),
        'tco' => array(
            'name' => 'task.tco',
            'header' => 'TCO',
            'headerHtmlOptions' => array('width' => '8%'),
            'htmlOptions' => array('style' => 'text-align:center;')
        ),
        'status' => array(
            'name' => 'status',
            'header' => 'Status',
            'headerHtmlOptions' => array('width' => '8%'),
            'htmlOptions' => array('style' => 'text-align:center;')
        ),
        array(
            'class' => 'CLinkColumn',
            'header' => '操作', //显示表名称
            'headerHtmlOptions' => array('width' => '6%'),
            'labelExpression' => '详情', //显示名称
            'urlExpression' => 'Yii::app()->createUrl("personTask/popView",array("id"=>$data->ptid))', //显示URL
//            'urlExpression' => 'Yii::app()->createUrl("personTask/view",array("id"=>$data->ptid))', //显示URL
            'linkHtmlOptions' => array('class' => 'iframe'),
            'htmlOptions' => array('style' => 'text-align:center;'),
        ),
        array(
            'class' => 'CCheckBoxColumn',
            'name' => 'tid',
            'id' => 'taskSelect',
            'selectableRows' => 2,
            'footer' => '<button type="button" onclick="GetCheckboxDel();" >Delete</button>',
            'htmlOptions' => array('style' => 'text-align:center;'),
        ),
    ),
));
?>
<?php
$this->widget('zii.widgets.grid.CGridView', array(
    'id' => 'task-grid',
    'dataProvider' => $searchModel->assignSearch($model->pdid),
    'filter' => $searchModel,
    'columns' => array(
		'taskid' => array(
            'name' => 'taskid',
            'header' => 'Taskid',
            'headerHtmlOptions' => array('width' => '5%'),
            'htmlOptions' => array('style' => 'text-align:center;')
        ),
		'tcode' => array(
            'name' => 'class.classname',
            'header' => 'Tcode',
            'headerHtmlOptions' => array('width' => '10%'),
            'htmlOptions' => array('style' => 'text-align:left;')
        ),
		'subcode' => array(
            'name' => 'task',
            'header' => 'Subcode',
            'headerHtmlOptions' => array('width' => '18%'),
            'htmlOptions' => array('style' => 'text-align:left;')
        ),
		'taskdetail' => array(
            'name' => 'taskdetail',
            'header' => 'Task Detail',
            'headerHtmlOptions' => array('width' => '50%'),
            'htmlOptions' => array('style' => 'text-align:left;')
        ),
        'tco',
        array(
            'class' => 'CCheckBoxColumn',
            'name' => 'taskid',
            'id' => 'taskSelect',
            'selectableRows' => 2,
            'footer' => '<button type="button" onclick="GetCheckbox();" >Select</button>',
            'htmlOptions' => array('style'=>'text-align:center;'),
        ),
    ),
));
?>
<script type="text/javascript">
/*<![CDATA[*/
var GetCheckbox = function (){
	var data=new Array();
    $("input:checkbox[name='taskSelect[]']").each(function (){
    	if($(this).attr("checked")=='checked'){
        	data.push($(this).val());
        }
    });
    if(data.length > 0){
        $.post('<?php echo CHtml::normalizeUrl(array('/personTask/assignTaskAjax'));?>',{'taskSelect[]':data,'pdid':<?=$model->pdid?>}, function (data) {
            var ret = $.parseJSON(data);
            if (ret != null && ret.success != null && ret.success) {
				alert(ret.msg);
				window.location.href = '<?php echo CHtml::normalizeUrl(array('/personDate/assignTask&id='.$model->pdid));?>';
        	}
        });
    }else{
    	alert("请选择要关联的任务!");
    }
}
var GetCheckboxDel = function (){
	var data=new Array();
    $("input:checkbox[name='taskSelect[]']").each(function (){
        if($(this).attr("checked")=='checked'){
            data.push($(this).val());
        }
    });
    if(data.length > 0){
        $.post('<?php echo CHtml::normalizeUrl(array('/personTask/removeTaskAjax')); ?>',{'taskSelect[]':data,'pdid':<?= $model->pdid ?>}, function (data) {
            var ret = $.parseJSON(data);
            if (ret != null && ret.success != null && ret.success) {
                alert(ret.msg);
                window.location.href = '<?php echo CHtml::normalizeUrl(array('/personDate/assignTask&id=' . $model->pdid)); ?>';
            }
        });
    }else{
        alert("请选择要删除的关联任务!");
    }
}
/*]]>*/
</script>